#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define pii pair<int,int>
#define fi first
#define se second
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=1e9+7;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n,k;
char mp[3005][3005]; 
int ans=0;
map<int,int>Mp[6];
void dfs(int x,int p){
	if(Mp[x][p]) return;
	Mp[x][p]=1;
	if(x==k+1){
		ans++;
//		For(i,1,n)For(j,1,n){
//			if(p&(1<<((i-1)*n+j-1))) cout<<"1";
//			else cout<<"0";
//			if(j==n)puts("");
//		}puts("");
		return;
	}
	For(i,1,n){
		For(j,1,n){
			if(p&(1<<((i-1)*n+j-1)))continue;
			if(i>1){
				if(p&(1<<((i-1-1)*n+j-1))){
					dfs(x+1,p|(1<<((i-1)*n+j-1)));
					continue;
				}
			}
			if(i<n){
				if(p&(1<<((i+1-1)*n+j-1))){
					dfs(x+1,p|(1<<((i-1)*n+j-1)));
					continue;
				}
			}
			if(j>1){
				if(p&(1<<((i-1)*n+j-1-1))){
					dfs(x+1,p|(1<<((i-1)*n+j-1)));
					continue;
				}
			}
			if(j<n){
				if(p&(1<<((i-1)*n+j+1-1))){
					dfs(x+1,p|(1<<((i-1)*n+j-1)));
					continue;
				}
			}
		}
	}
}int sum;
inline bool check(int i,int j){
	if(mp[i-1][j]=='#')return 1;
	else if(mp[i+1][j]=='#')return 1;
	else if(mp[i][j+1]=='#')return 1;
	else if(mp[i][j-1]=='#')return 1;
	return 0;
}inline int ksm(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=res*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}return res;
}bool vis[3005][3005];
inline int find(int i,int j){
	if(i<0||j<0||i>n||j>n)return 0;
	if(check(i,j))return 0;
	int ans=sum;
	if(vis[i][j+1])ans--;
	if(vis[i][j-1])ans--;
	if(vis[i-1][j])ans--;
	if(vis[i+1][j])ans--;
	return ans;
}inline int Find(int i,int j){
	if(i<0||j<0||i>n||j>n)return 0;
	if(check(i,j))return 0;
	int ans=sum;
	if(vis[i][j+1])ans--;
	if(vis[i][j-1])ans--;
	if(vis[i-1][j])ans--;
	if(vis[i+1][j])ans--;
	return ans*(ans-1)/2%Mod;
}inline int calc(int i,int j){
	int ans=0;
	if(mp[i][j+1]=='.'&&!check(i,j+1))ans++;
	if(mp[i][j-1]=='.'&&!check(i,j-1))ans++;
	if(mp[i+1][j]=='.'&&!check(i+1,j))ans++;
	if(mp[i-1][j]=='.'&&!check(i-1,j))ans++;
	return ans;
}
inline int work(int x,int y,int i,int j){
	if(check(i,j)) return 0;
	return find(x,y)+find(i,j)-sum;
}
inline int Calc(int i,int j){
	if(i<0||j<0||i>n||j>n)return 0;
	if(check(i,j))return 0;
	int ans=0;
	if(mp[i][j+1]=='.'&&!check(i,j+1))ans+=work(i,j,i,j+1);
	if(mp[i][j-1]=='.'&&!check(i,j-1))ans+=work(i,j,i,j-1);
	if(mp[i+1][j]=='.'&&!check(i+1,j))ans+=work(i,j,i+1,j);
	if(mp[i-1][j]=='.'&&!check(i-1,j))ans+=work(i,j,i-1,j);
	return ans;
}int fx[5]={0,1,0,-1},fy[5]={1,0,-1,0};
inline bool near(int i,int j,int x,int y){
	return abs(i-x)+abs(j-y)<=1;
}
signed main(){
	freopen("brick.in","r",stdin);
	freopen("brick.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read(),k=read();
	For(i,1,n)scanf("%s",mp[i]+1);
	if(k==1){
		For(i,1,n){
			For(j,1,n){
				if(mp[i][j]=='#')continue;
				if(mp[i-1][j]=='#')ans++;
				else if(mp[i+1][j]=='#')ans++;
				else if(mp[i][j+1]=='#')ans++;
				else if(mp[i][j-1]=='#')ans++;
			}
		}
		printf("%lld\n",ans);
		return 0;
	}
	if(n<=5){
		int p=0;
		For(i,1,n){
			For(j,1,n){
				if(mp[i][j]=='#')p|=(1<<((i-1)*n+j-1));
			}
		}
		dfs(1,p);
		printf("%lld\n",ans);
		return 0;
	}
	if(k==2){
		For(i,1,n){
			For(j,1,n){
				if(mp[i][j]=='.'&&check(i,j))sum++;
			}
		}ans+=sum*(sum-1)/2;ans%=Mod;
		For(i,1,n){
			For(j,1,n){
				if(mp[i][j]=='.'&&check(i,j)){
					if(mp[i][j+1]=='.'&&!check(i,j+1))ans++;
					if(mp[i][j-1]=='.'&&!check(i,j-1))ans++;
					if(mp[i+1][j]=='.'&&!check(i+1,j))ans++;
					if(mp[i-1][j]=='.'&&!check(i-1,j))ans++;
				}
			}
		}
		printf("%lld\n",ans%Mod);
		return 0;
	}
	if(k==3){
		For(i,1,n){
			For(j,1,n){
				if(mp[i][j]=='.'&&check(i,j))sum++;
			}
		}ans+=sum*(sum-1)%Mod*(sum-2)%Mod*ksm(6,Mod-2)%Mod;
		For(i,0,n+1) For(j,0,n+1) vis[i][j]=0;
		For(i,1,n){
			For(j,1,n){
				if(mp[i][j]=='.'&&check(i,j)){
					vis[i][j]=1;
					if(mp[i][j+1]=='.')ans+=find(i,j+1);
					if(mp[i][j-1]=='.')ans+=find(i,j-1);
					if(mp[i+1][j]=='.')ans+=find(i+1,j);
					if(mp[i-1][j]=='.')ans+=find(i-1,j);
				}
			}
		}
		For(i,1,n){
			For(j,1,n){
				if(mp[i][j]=='.'&&check(i,j)){
					if(mp[i][j+1]=='.'&&!check(i,j+1))ans+=calc(i,j+1);
					if(mp[i][j-1]=='.'&&!check(i,j-1))ans+=calc(i,j-1);
					if(mp[i+1][j]=='.'&&!check(i+1,j))ans+=calc(i+1,j);
					if(mp[i-1][j]=='.'&&!check(i-1,j))ans+=calc(i-1,j);
					int k=calc(i,j);
					ans+=k*(k-1)/2;
				}
			}
		}
		printf("%lld\n",ans%Mod);
		return 0;
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

